import os

from IO.DatabaseIO import Database
from Methods import *

class Task(object):
    def __init__(self):
        self.init()

    def init(self):
        self.protein_file = None
        self.orth_file = None
        self.method = None
        self.target_taxon_id = None
        self.db = None         
        self.method_list = MethodToCalculator.keys()
        if len(self.method_list) == 0:
            raise ValueError('No methods found')
        self.status = 'new'   # this tells where the task goes
        
        #draw setting
        self.node_size = 10
        self.node_color = 'red'
        self.node_shape = 'o'
        self.layout = 'spring'
        self.font_size = '1'
        self.limit = 50

    def init_db(self):
        if self.protein_file == None or self.orth_file == None:
            raise ValueError('files not chosen')
        self.db = Database(self.protein_file, self.orth_file)
        self.db.init_data()
        self.status = 'database set'

    def renew(self):
        self.init()

    def set_protein_file(self, protein_file):
        # need some checks here
        self.protein_file = protein_file

    def set_orth_file(self, orth_file):
        # need some checks here
        self.orth_file = orth_file

    def set_target_taxon(self, taoxn_id):
        # need some checks here
        self.target_taxon_id = taoxn_id

    def set_method(self, method_name):
        self.method_name = method_name
        #self.method = method(method_name, self.db)

    def calculate(self):
        self.method = method(self.method_name, self.db)
        self.method.calculate()
        self.status = 'calculated'
        
    def set_node_size(self, node_size):
        self.node_size = node_size
    
    def set_node_color(self, node_color):
        self.node_color = node_color
    
    def set_node_shape(self, node_shape):
        self.node_shape = node_shape
    
    def set_layout(self, layout):
        self.layout = layout
    
    def set_font_size(self, font_size):
        self.font_size = font_size
        
    def set_edge_limit(self, edge_limit):
        self.limit = edge_limit
        
        
        
#END